package com.jiangyg.mall.coupon.service;

import com.jiangyg.mall.core.support.restful.Pagination;
import com.jiangyg.mall.coupon.dao.CouponDao;
import com.jiangyg.mall.coupon.dto.CouponDTO;
import com.jiangyg.mall.coupon.entity.Coupon;
import com.jiangyg.mall.coupon.vo.CouponVO;
import com.jiangyg.mall.db.mybatis.BaseServiceImpl;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CouponServiceImpl extends BaseServiceImpl<CouponDao, Coupon> implements CouponService {

    @Autowired
    public CouponServiceImpl(CouponDao couponDao) {
        super(couponDao);
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public Pagination<CouponVO> selectPagination(Pagination<CouponVO> pagination) throws Exception {
        return this.executeSelectPagination(pagination, CouponVO.class);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean saveOrUpdate(CouponDTO dto) throws Exception {
        return this.executeSaveOrUpdate(dto) > 0;
    }

    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED, readOnly = true)
    public CouponVO selectById(Long couponId) throws Exception {
        return this.executeSelectById(couponId, CouponVO.class);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public boolean delete(List<Long> couponIds) {
        return this.baseMapper.deleteBatchIds(couponIds) > 0;
    }

}
